using System;
using System.Linq;
using Comteck.Entities.Sys;

namespace Comteck.Ktt.Services.SeedData {
  /// <summary>
  /// 打印模版
  /// </summary>
  public class _20250429001_PrintTemplate : IDataSeed {
    /// <summary>
    /// 
    /// </summary>
    /// <param name="context"></param>
    public void Init(AppDbContext context) {

      // 打印模版
      if (!context.PrintTemplate.Any()) {
        context.PrintTemplate.Add(new PrintTemplate {
          Id = "98f7ecff-f61c-4b95-a575-50607abc2cdf",
          Name = "订单打印",
          Status = 1,
          MenuId = "4030",
          Data = $@"<?xml version=""1.0"" encoding=""utf-8""?>
<Report ScriptLanguage=""CSharp"" ReportInfo.Created=""09/23/2018 21:45:29"" ReportInfo.Modified=""04/25/2025 11:23:26"" ReportInfo.CreatorVersion=""2013.2.5.0"">
  <Dictionary>
    <TableDataSource Name=""table0"" ReferenceName=""Data.table0"" DataType=""System.Int32"" Enabled=""true"">
      <Column Name=""id"" DataType=""System.String""/>
      <Column Name=""code"" DataType=""System.String""/>
      <Column Name=""description"" DataType=""System.String""/>
      <Column Name=""status"" DataType=""System.Int32""/>
      <Column Name=""GroupNumber"" DataType=""System.String""/>
      <Column Name=""DeliveryCode"" DataType=""System.String""/>
      <Column Name=""GroupTitle"" DataType=""System.String""/>
      <Column Name=""BuyUserName"" DataType=""System.String""/>
      <Column Name=""BuyUserDesc"" DataType=""System.String""/>
      <Column Name=""PayDate"" DataType=""System.DateTime""/>
      <Column Name=""GroupDesc"" DataType=""System.String""/>
      <Column Name=""GoodsCount"" DataType=""System.Int32""/>
      <Column Name=""GoodsWeight"" DataType=""System.Decimal""/>
      <Column Name=""GoodsAmt"" DataType=""System.Decimal""/>
      <Column Name=""FreightAmt"" DataType=""System.Decimal""/>
      <Column Name=""DiscountAmt"" DataType=""System.Decimal""/>
      <Column Name=""TotalAmt"" DataType=""System.Decimal""/>
      <Column Name=""ReturnAmt"" DataType=""System.Decimal""/>
      <Column Name=""GroupName"" DataType=""System.String""/>
      <Column Name=""DeliveryTypeName"" DataType=""System.String""/>
      <Column Name=""SelfOrgId"" DataType=""System.Int32""/>
      <Column Name=""SelfOrgName"" DataType=""System.String""/>
      <Column Name=""SelfOrgContacts"" DataType=""System.String""/>
      <Column Name=""SelfOrgPhone"" DataType=""System.String""/>
      <Column Name=""Recipient"" DataType=""System.String""/>
      <Column Name=""RecipientPhone"" DataType=""System.String""/>
      <Column Name=""Province"" DataType=""System.String""/>
      <Column Name=""City"" DataType=""System.String""/>
      <Column Name=""District"" DataType=""System.String""/>
      <Column Name=""Street"" DataType=""System.String""/>
      <Column Name=""RecipientAddress"" DataType=""System.String""/>
      <Column Name=""PrintNum"" DataType=""System.Int32""/>
      <Column Name=""SeqNo"" DataType=""System.Int32""/>
      <Column Name=""ImportBatchNo"" DataType=""System.String""/>
      <Column Name=""ImportTime"" DataType=""System.DateTime""/>
      <Column Name=""SelfOrgAddress"" DataType=""System.String""/>
      <Column Name=""MainOrderFlag"" DataType=""System.Int32""/>
      <Column Name=""MainCode"" DataType=""System.String""/>
      <Column Name=""MainGroupNumber"" DataType=""System.String""/>
      <Column Name=""MainSplitCount"" DataType=""System.Int32""/>
      <Column Name=""IsFirstInSelfOrg"" DataType=""System.Int32""/>
    </TableDataSource>
    <TableDataSource Name=""table1"" ReferenceName=""Data.table1"" DataType=""System.Int32"" Enabled=""true"">
      <Column Name=""id"" DataType=""System.String""/>
      <Column Name=""OrderId"" DataType=""System.String""/>
      <Column Name=""ProductId"" DataType=""System.Int32""/>
      <Column Name=""ProductName"" DataType=""System.String""/>
      <Column Name=""SeqNo"" DataType=""System.Int32""/>
      <Column Name=""Qty"" DataType=""System.Int32""/>
      <Column Name=""Weight"" DataType=""System.Decimal""/>
      <Column Name=""TotalWeight"" DataType=""System.Decimal""/>
      <Column Name=""GroupDetailId"" DataType=""System.String""/>
    </TableDataSource>
    <Relation Name=""table0_table1"" ParentDataSource=""table0"" ChildDataSource=""table1"" ParentColumns=""id"" ChildColumns=""OrderId"" Enabled=""true""/>
    <Parameter Name=""Login_Code"" DataType=""System.String""/>
    <Parameter Name=""Login_Name"" DataType=""System.String""/>
    <Total Name=""TotalQty"" Expression=""[table1.Qty]"" Evaluator=""Data3"" PrintOn=""PageFooter1""/>
  </Dictionary>
  <ReportPage Name=""Page1"" PaperWidth=""70"" PaperHeight=""136"" LeftMargin=""2"" TopMargin=""2"" RightMargin=""2"" BottomMargin=""2"" FirstPageSource=""15"" OtherPagesSource=""15"" Fill.Color=""White"">
    <DataBand Name=""Data1"" Width=""249.48"" Height=""158.76"" CanGrow=""true"" StartNewPage=""true"" DataSource=""table0"">
      <TextObject Name=""Text2"" Top=""66.15"" Width=""245.7"" Height=""32.13"" CanGrow=""true"" Text=""送货点：[table0.SelfOrgName]"" Format=""Date"" Format.Format=""d"" VertAlign=""Center"" Font=""微软雅黑, 9.75pt, style=Bold""/>
      <TextObject Name=""Text34"" Top=""97.05"" Width=""245.7"" Height=""37.8"" CanGrow=""true"" Text=""收货地址：[table0.RecipientAddress][IIf(Length([table0.BuyUserDesc]) &gt; 0,&quot;，&quot;,&quot;&quot;)][table0.BuyUserDesc]&#13;&#10;"" Format=""Date"" Format.Format=""d"" VertAlign=""Center"" Font=""微软雅黑, 9.75pt, style=Bold""/>
      <TextObject Name=""Text51"" Top=""47.25"" Width=""245.7"" Height=""18.9"" CanGrow=""true"" Text=""联系人：[table0.Recipient] [table0.RecipientPhone]"" VertAlign=""Center"" Font=""微软雅黑, 9.75pt, style=Bold""/>
      <LineObject Name=""Line1"" Top=""39.35"" Width=""255.15""/>
      <TextObject Name=""Text68"" Top=""9.45"" Width=""75.6"" Height=""18.9"" Text=""[IIf([table0.MainSplitCount] &gt; 1,&quot;共&quot; + [table0.MainSplitCount] + &quot;件&quot;,&quot;&quot;)]"" VertAlign=""Center"" Font=""微软雅黑, 12pt, style=Bold""/>
      <TextObject Name=""TextStar"" Left=""65"" Top=""9.45"" Width=""30"" Height=""18.9"" Text=""[IIf([table0.IsFirstInSelfOrg] &gt; 0,&quot;★&quot;,&quot;&quot;)]""   VertAlign=""Center"" HorzAlign=""Center"" Font=""微软雅黑, 18pt, style=Bold"" TextColor=""Red""/>
      <BarcodeObject Name=""Barcode1"" Left=""98.6"" Width=""146.9"" Height=""37.8"" AutoSize=""false"" DataColumn=""table0.DeliveryCode"" Text=""1308059711723"" Barcode=""Code128"" Barcode.CalcCheckSum=""false"" Barcode.AutoEncode=""true""/>
      <TextObject Name=""Text71"" Top=""135.3"" Width=""245.7"" Height=""22.68"" CanGrow=""true"" Text=""团长备注：[table0.GroupDesc]&#13;&#10;"" Format=""Date"" Format.Format=""d"" VertAlign=""Center"" Font=""微软雅黑, 9.75pt, style=Bold""/>
      <DataBand Name=""Data3"" Top=""195.11"" Width=""249.48"" Height=""34.02"" CanGrow=""true"" DataSource=""table1"">
        <TextObject Name=""Text11"" Width=""198.45"" Height=""22.68"" CanGrow=""true"" GrowToBottom=""true"" Text=""[table1.ProductName]"" VertAlign=""Center"" Font=""微软雅黑, 9.75pt, style=Bold""/>
        <TextObject Name=""Text20"" Left=""200"" Width=""47.25"" Height=""22.68"" CanGrow=""true"" GrowToBottom=""true"" Text=""[table1.Qty]"" Format=""Custom"" Format.Format=""0.###"" HorzAlign=""Right"" VertAlign=""Center"" Font=""微软雅黑, 14pt, style=Bold""/>
        <DataHeaderBand Name=""DataHeader1"" Top=""162.76"" Width=""249.48"" Height=""28.35"">
          <TextObject Name=""Text15"" Top=""2"" Width=""198.45"" Height=""22.68"" Text=""商品"" VertAlign=""Center"" Font=""微软雅黑, 12pt, style=Bold""/>
          <TextObject Name=""Text21"" Left=""200"" Top=""2"" Width=""47.25"" Height=""22.68"" Text=""数量"" HorzAlign=""Right"" VertAlign=""Center"" Font=""微软雅黑, 12pt, style=Bold""/>
          <LineObject Name=""Line4"" Top=""-2"" Width=""255.15""/>
        </DataHeaderBand>
        <DataFooterBand Name=""DataFooter1"" Top=""233.13"" Width=""249.48"" Height=""47.25"" PrintOnBottom=""true"" RepeatOnEveryPage=""true"">
          <LineObject Name=""Line2"" Top=""-1"" Width=""255.15""/>
          <TextObject Name=""Text69"" Top=""9.45"" Width=""170.1"" Height=""28.35"" CanBreak=""false"" Text=""[table0.GroupNumber]"" VertAlign=""Center"" Font=""微软雅黑, 21.75pt, style=Bold""/>
          <TextObject Name=""Text70"" Left=""151.2"" Top=""9.45"" Width=""94.5"" Height=""28.35"" Text=""[TotalQty]"" HorzAlign=""Right"" VertAlign=""Center"" Font=""微软雅黑, 21.75pt, style=Bold""/>
        </DataFooterBand>
        <Sort>
          <Sort Expression=""[table1.SeqNo]""/>
          <Sort Expression=""[table1.ProductName]""/>
        </Sort>
      </DataBand>
    </DataBand>
    <PageFooterBand Name=""PageFooter1"" Top=""284.38"" Width=""249.48"" Height=""30.24"">
      <TextObject Name=""Text65"" Top=""5.45"" Width=""141.75"" Height=""20.79"" Text=""发货人：118水果团"" Format=""Custom"" Format.Format=""0.##"" VertAlign=""Center"" Font=""微软雅黑, 9.75pt""/>
      <TextObject Name=""Text67"" Left=""144.2"" Top=""6.45"" Width=""103.95"" Height=""18.9"" Text=""15824138888"" Format=""Custom"" Format.Format=""0.##"" HorzAlign=""Right"" VertAlign=""Center"" Font=""微软雅黑, 9.75pt""/>
      <LineObject Name=""Line3"" Left=""1.45"" Top=""-1.1"" Width=""255.15""/>
    </PageFooterBand>
  </ReportPage>
</Report>
",
          IsSystem = 1,
          SeqNo = 0,
          Description = null,
        });

        context.PrintTemplateData.Add(new PrintTemplateData() {
          Id = Guid.NewGuid().ToString(),
          TemplateId = "98f7ecff-f61c-4b95-a575-50607abc2cdf",
          Name = "table0",
          Sql = "SELECT  * FROM saleorder WHERE id in @ids ORDER BY selforgname, recipientaddress",
          SeqNo = 0,
          Description = "主表"
        });

        context.PrintTemplateData.Add(new PrintTemplateData() {
          Id = Guid.NewGuid().ToString(),
          TemplateId = "98f7ecff-f61c-4b95-a575-50607abc2cdf",
          Name = "table1",
          Sql = "select * from saleorderdetail where orderid in @ids order by seqno",
          SeqNo = 1,
          Description = "明细"
        });
        context.SaveChanges();
      }
    }
  }
}
